<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:rich="http://richfaces.org/rich">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Consultar Plan</title>
    </head> 

    <ui:composition template="./../../resources/template/facesTemplate.xhtml">
        <ui:define name="content">
            <h:body>
                <h:form id="frm">
                    <div>
                        <fieldset>
                            <h3><h:outputText value="#{loginBean.ubicacion}"/></h3>
                            <div class="tablaForm">
                                <div class="fila">
                                    <div class="etiq"><label for="modelo">Seleccione un Modelo</label></div>
                                    <div class="cont"><h:selectOneMenu id="modelo" value="#{asignarPlanBean.moto.modelo}">
                                            <f:selectItems value="#{asignarPlanBean.listaMoto}"/>
                                            <f:ajax listener="#{asignarPlanBean.obtenerListaStock()}" render="stock"/>
                                        </h:selectOneMenu><rich:messages for="modelo"/></div>
                                </div>
                                <div class="fila">
                                    <div class="etiq"><label for="stock">Seleccione una Moto</label></div>
                                    <div class="cont"><h:selectOneMenu id="stock" value="#{asignarPlanBean.stockId}">
                                            <f:selectItems value="#{asignarPlanBean.listaStock}"/>
                                            <f:ajax event="blur" render="@this"/>
                                            <rich:validator/>
                                        </h:selectOneMenu><rich:messages for="stock"/></div>
                                </div>
                                <div class="fila">
                                    <div class="etiq"><label for="plan">Seleccione un Plan</label></div>
                                    <div class="cont"><h:selectOneMenu id="plan" value="#{asignarPlanBean.planId}">
                                            <f:selectItems value="#{asignarPlanBean.listaPlan}"/>
                                            <f:ajax render="@this"/>
                                            <rich:validator/>
                                        </h:selectOneMenu><rich:messages for="plan"/></div>
                                </div>
                                <div class="fila">
                                    <div class="etiq"><label for="cantidadEntrega" >Cantidad de Opciones:</label></div>
                                    <div class="cont"><h:inputText id="cantidadEntrega" size="4" maxlength="2" styleClass="d_num" value="#{asignarPlanBean.cantidadEntregas}">
                                            <rich:validator/>
                                            <f:ajax render="@this"/>
                                        </h:inputText><rich:messages for="cantidadEntrega"/>
                                    </div>
                                </div>
                            </div>
                            <div>
                                <h:panelGroup id="panelGrilla">
                                    <h:panelGroup rendered="#{empty asignarPlanBean.listaDePlanes}">
                                        <div class="botonera">
                                            <h:commandButton id="asignar" type="submit" value="Generar Grilla" action="#{asignarPlanBean.asignarPlan()}"/>
                                        </div>
                                    </h:panelGroup>
                                    <h:panelGroup rendered="#{not empty asignarPlanBean.listaDePlanes}">
                                        <table id="tabla" class="tablaDatos">
                                            <thead>
                                                <tr>
                                                    <th colspan="20">
                                                        <div style="display: inline-block;clear: left;"><h:outputText value="#{asignarPlanBean.motostock.moto.getlabel()}"/></div>
                                                        <div style="display: inline-block;clear: right;"><h:outputText value="Precio Contado:"/>
                                                            <h:outputText value="#{asignarPlanBean.motostock.precioContado}">
                                                                <f:convertNumber pattern="#{asignarPlanBean.monedaPattern}"/>
                                                            </h:outputText></div>
                                                    </th></tr>
                                                <tr>
                                                    <ui:repeat value="#{asignarPlanBean.listaDeEntrega}" var="row">
                                                        <th>
                                                            <h:panelGroup rendered="#{row.intValue() eq 0}">
                                                                <h:outputText value="Cuota Corrida"/>
                                                            </h:panelGroup>
                                                            <h:panelGroup rendered="#{row.intValue() gt 0}">
                                                                <h:outputText value="#{row}">
                                                                    <f:convertNumber pattern="#{asignarPlanBean.monedaPattern}"/>
                                                                </h:outputText>
                                                            </h:panelGroup>
                                                        </th>
                                                    </ui:repeat>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <ui:repeat value="#{asignarPlanBean.listaDePlanes}" var="v">
                                                    <tr>
                                                        <th><h:outputText value="#{v.numeroCuota}"/></th>
                                                        <ui:repeat value="#{v.listaMontoCuotas}" var="cuota">
                                                            <td>
                                                                <h:outputText value="#{cuota}">
                                                                    <f:convertNumber pattern="#{asignarPlanBean.monedaPattern}"/>
                                                                </h:outputText>
                                                            </td>
                                                        </ui:repeat>
                                                    </tr>
                                                </ui:repeat>
                                            </tbody>
                                        </table>
                                        <h:commandLink target="_blank" action="#{asignarPlanBean.generarReporte()}">Imprimir...</h:commandLink>
                                        <div class="botonera">
                                            <h:commandButton value="Asignar" action="#{asignarPlanBean.asignar}"/>
                                            <h:commandButton value="Cancelar" immediate="true" action="main"/>
                                        </div>
                                    </h:panelGroup>
                                </h:panelGroup>
                            </div>
                        </fieldset>
                    </div>
                </h:form>
            </h:body>
        </ui:define>
    </ui:composition>
</html>
